package com.ansuenjob.manager.impl;

import java.util.ArrayList;
import java.util.List;

import com.ansuenjob.db.dao.QueryDao;
import com.ansuenjob.manager.PPTAManager;
import com.ansuenjob.model.BstInformationBase;
import com.ansuenjob.model.simple.InformationBaseSimple;
import com.ansuenjob.util.Constants;
import com.ansuenjob.util.Page;

public class PPTAManagerImpl implements PPTAManager {

	public Page findPPtAList(int currentPage, int pageSize,String section) {
		QueryDao dao = new QueryDao();
		BstInformationBase ex = new BstInformationBase();
		ex.setTypeName(section);
		Page page = dao.findByExampleInPageWithSort(BstInformationBase.class, ex, null, "updateDate", Constants.DESC, currentPage, pageSize);
		return page;
	}

	public Page findSimplePPtAList(int currentPage, int pageSize, String section) {
		Page p = findPPtAList(currentPage, pageSize, section);
		List<InformationBaseSimple> st = new ArrayList<InformationBaseSimple>();
		List<BstInformationBase> temp = p.getPageList();
		InformationBaseSimple simple;
		for (BstInformationBase bstInformationBase : temp) {
			simple = new InformationBaseSimple(bstInformationBase.getNid(), bstInformationBase.getTitle(), 
					bstInformationBase.getTypeName(), bstInformationBase.getUpdateDate());
			st.add(simple);
		}
		p.setPageList(st);
		return p;
	}

	public BstInformationBase findInbormationBaseById(int id) {
		QueryDao dao = new QueryDao();
		BstInformationBase bib = dao.findById(BstInformationBase.class, id);
		return bib;
	}
	
	

}
